package cn.middle.basic.service.impl;


import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.middle.common.base.mapper.BaseMapper;
import com.middle.common.base.service.impl.BaseServiceImpl;

import cn.middle.basic.entity.SysDictionaryItem;
import cn.middle.basic.entity.SysDictionaryType;
import cn.middle.basic.mapper.SysDictionaryItemMapper;
import cn.middle.basic.mapper.SysDictionaryTypeMapper;
import cn.middle.basic.service.SysDictionaryTypeService;

@Service
public class SysDictionaryTypeServiceImpl extends BaseServiceImpl<SysDictionaryType>
		implements SysDictionaryTypeService {

	
	@Autowired
	private SysDictionaryTypeMapper mapper; 
	
	@Autowired
	private SysDictionaryItemMapper itemMapper;
	
	@Override
	public BaseMapper<SysDictionaryType> getDao() {
		return mapper;
	}
	@Override
	public List<SysDictionaryItem> getItemsByCode(String code) {
		return itemMapper.findByCode(code);
	}
	@Transactional(rollbackFor = Exception.class)
	@Override
	public void deleteDictionaryTypeAndItems(Long id) {
		SysDictionaryType dictionaryType = this.mapper.selectByPrimaryKey(id);
		if(dictionaryType != null) { //表示存在该字典
			itemMapper.deleteByDictionayTypeId(id);  //删除条目
			mapper.deleteByPrimaryKey(id);  //删除字典
		}
	}



}
